package com.tcm.day03;

public class Code02_MyQueue {

    public static class MyQueue {
        Node head;
        Node tail;
        int size;

        public MyQueue() {
            head = null;
            tail = null;
            size = 0;
        }

        public void offer(int val) {
            Node node = new Node(val);
            if (null == tail) {
                head = tail = node;
            } else {
                tail.next = node;
                tail = tail.next;
            }
            size++;
        }

        public int poll() {

            int ans = -1;
            if (head != null) {
                ans = head.val;
                head = head.next;
                size--;
            }
            if (head == null) {
                tail = null;
            }
            return ans;
        }

        public int peek() {
            if (null == head) {
                return -1;
            } else {
                return head.val;
            }
        }
    }

}
